<script src="/js/jquery-3.1.0.min.js"></script>
<script src="/js/jquery.orgchart.js"></script>
<link rel="stylesheet" href="/css/jquery.orgchart.css">
<div class="row" style="height:100%;">
	<div class="col-lg-12" style="border-right:1px solid #e6e6e6;padding-right:0px;">
		<h1 class="site-h1" style="background-color:#FFFFFF;">
			IVR菜单设置，接入号码：${extention.extention!''}
		</h1>
		<div class="row">
			<div class="col-lg-12">
				<div class="ukefu-ivrchat" id="chart-container"></div>
			</div>	
		</div>
	</div>	
</div>
<script language="javascript">
	var temp = [
		<#if ivrMenuList?? && ivrMenuList?size gt 0>
       	<#list ivrMenuList as ivrMenu>
        	{
       		'id': "${ivrMenu.id!''}",
   			'parentid': "<#if ivrMenu.parentid==extention.id>0<#else>${ivrMenu.parentid!''}</#if>",
			'name': '${ivrMenu.name!''}<#if ivrMenu.type=='menusub'><a href="/admin/callcenter/ivr/menu/add.html?ivrid=${ivrMenu.id!''}&hostid=${extention.hostid!''}" data-toggle="ajax" data-width="950" data-height="550" data-title="新增下级IVR节点" class="ukefu-ivr-design" title="新增下级IVR节点"><i class="layui-icon">&#xe61f;</i></a></#if><a href="/admin/callcenter/ivr/menu/delete.html?id=${ivrMenu.id!''}&hostid=${extention.hostid!''}&extentionid=${extention.id!''}" data-toggle="load" data-target="#callCenterContent" class="ukefu-ivr-design" title="删除IVR节点"><i class="layui-icon">&#xe640;</i></a><a href="/admin/callcenter/ivr/menu/edit.html?id=${ivrMenu.id!''}&hostid=${extention.hostid!''}" data-toggle="ajax" data-width="950" data-height="550" data-title="编辑${ivrMenu.extention!''}节点" class="ukefu-ivr-design" title="编辑IVR节点"><i class="layui-icon">&#xe631;</i></a>',
	        'title': '<#if mediaMap?? && ivrMenu.greetlong?? && mediaMap[ivrMenu.greetlong]??><div class="item">欢迎语音：${mediaMap[ivrMenu.greetlong]}</div></#if><#if mediaMap?? && ivrMenu.invalidsound?? && mediaMap[ivrMenu.invalidsound]??><div class="item">无效输入：${mediaMap[ivrMenu.invalidsound]}</div></#if><#if mediaMap?? && ivrMenu.exitsound?? && mediaMap[ivrMenu.exitsound]??><div class="item">退出语音：${mediaMap[ivrMenu.exitsound]}</div></#if><div class="item">拨号键：${ivrMenu.digits!''}</div><div class="item">类型：<#if ivrMenu.type=='toinline'>转内线<#elseif ivrMenu.type=='tooutline'>转外线<#elseif ivrMenu.type=='menuexecapp'>执行应用操作<#elseif ivrMenu.type=='menuexit'>挂断<#elseif ivrMenu.type=='menusub'>转子菜单<#elseif ivrMenu.type=='menuback'>转上级<#elseif ivrMenu.type=='menutop'>转根目录<#elseif ivrMenu.type=='menuplaysound'>播放语音文件</#if></div><#if mediaMap?? && ivrMenu.type=='menuplaysound' && ivrMenu.playsound!='' && mediaMap[ivrMenu.playsound]??><div class="item">播放语音文件：${mediaMap[ivrMenu.playsound]}</div></#if><#if ivrMenu.type=='toinline' || ivrMenu.type=='tooutline'><div class="item">号码：${ivrMenu.param!''}</div></#if><#if ivrMenu.type=='menuexecapp'><div class="item">应用代码：${ivrMenu.param!''}</div></#if>',
	        'children': []
        	},
		</#list>
       	</#if>
      	];
	
	var result = [] ;
	function GetData(ivr,temp){
		var v = ivr ;
		var childIvr = GetByParentid(ivr.id,temp);
		if(childIvr.length > 0){
			for(var i in childIvr){
				v.children.push(GetData(childIvr[i],temp));
			}
		}
		return v ; 
	}
	function GetByParentid(id, arry) {
        var newArry = [];
        for (var i in arry) {
            if (arry[i].parentid == id)
                newArry.push(arry[i]);
        }
        return newArry;
    }
	for(var k in temp){
		if(temp[k].parentid=='0'){
			this.result.push(GetData(temp[k],temp));
		}
	}
	var datascource = {
			'id':'${extention.id!''}',
			'name': '${extention.extention!''}<a href="/admin/callcenter/ivr/menu/add.html?extentionid=${extention.id!''}&hostid=${extention.hostid!''}" data-toggle="ajax" data-width="950" data-height="550" data-title="新增下级IVR节点" class="ukefu-ivr-design" title="新增下级IVR节点"><i class="layui-icon">&#xe61f;</i></a><a href="/admin/callcenter/ivr/edit.html?id=${extention.id!''}&hostid=${extention.hostid!''}" data-toggle="ajax" data-width="950" data-height="550" data-title="编辑${extention.extention!''}节点" class="ukefu-ivr-design" title="编辑IVR节点"><i class="layui-icon">&#xe631;</i></a>',
	        'title': '<#if mediaMap?? && extention.greetlong?? && mediaMap[extention.greetlong]??>欢迎语音：${mediaMap[extention.greetlong]}<br/></#if><#if mediaMap?? && extention.invalidsound?? && mediaMap[extention.invalidsound]??>无效输入：${mediaMap[extention.invalidsound]}<br/></#if><#if mediaMap?? && extention.exitsound?? && mediaMap[extention.exitsound]??>退出语音：${mediaMap[extention.exitsound]}<br/></#if><#if mediaMap?? && extention.ttsvoice?? && mediaMap[extention.ttsvoice]??>转接语音：${mediaMap[extention.ttsvoice]}<br/></#if><#if mediaMap?? && extention.greetshort?? && mediaMap[extention.greetshort]??>欢迎提示短语音：${mediaMap[extention.greetshort]}<br/></#if>超时次数：最大${extention.maxtimeouts!''}次<br/>超时时间：<#if extention.timeout?? && extention.timeout!=0>${extention.timeout!''}<#else>0</#if>毫秒',
	        'children': result
	};
	$('#chart-container').orgchart({
	    'data': datascource,
	    'nodeContent': 'title',
	    'draggable': true,
	    'dropCriteria': function($draggedNode, $dragZone, $dropZone) {
	        if ($draggedNode.find('.content').text().indexOf('manager') > -1 && $dropZone.find('.content').text().indexOf('engineer') > -1) {
	            return false;
	        }
	        return true;
	    }
	}).children('.orgchart').on('nodedropped.orgchart',
		function(event) {
		//拖拽功能
	   	 console.log('draggedNode:' + event.draggedNode.children('.title').text() + ', dragZone:' + event.dragZone.children('.title').text() + ', dropZone:' + event.dropZone.children('.title').text());
	   	 var draggedNodeId = event.draggedNode.find('.id').prevObject[0].id;
	   	 var dropZoneId = event.dropZone.find('.id').prevObject[0].id;
	   	 loadURL("/admin/callcenter/ivr/menu/drag.html?hostid=${extention.hostid!''}&extentionid=${extention.id!''}&draggedNodeId="+draggedNodeId+"&dropZoneId="+dropZoneId,"#callCenterContent");
	});
</script>
